package com.leoman.plz_p.views.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.leoman.plz_p.R;
import com.leoman.plz_p.interfaces.CommonInputInfoView;
import com.leoman.plz_p.presenter.CommonInputInfoPresenter;
import com.leoman.plz_p.weidget.NavBar;

import butterknife.Bind;
import cn.com.corelib.base.BaseActivity;

/**
 * 通用的输入页面
 */
public class CommonInputInfoActivity extends BaseActivity<CommonInputInfoView, CommonInputInfoPresenter> implements CommonInputInfoView {

    @Bind(R.id.nav)
    NavBar nav;
    @Bind(R.id.et_input)
    EditText etInput;
    @Bind(R.id.tv_tips)
    TextView tvTips;

    public static final String KEY_TYPE = "KEY_TYPE";
    @Bind(R.id.tv_text)
    TextView tvText;

    public static Intent getLaunchIntent(Context context, int type) {
        Intent intent = new Intent(context, CommonInputInfoActivity.class);
        intent.putExtra(KEY_TYPE, type);
        return intent;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.ac_common_input_info;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        int type = getIntent().getIntExtra(KEY_TYPE, -1);
        switch (type) {
            case 0:
                nav.setTitle("修改昵称");
                tvText.setText("昵称");
                etInput.setHint("请输入昵称");
                tvTips.setText(R.string.input_hint_1);
                nav.setRightText("保存", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (TextUtils.isEmpty(getText(etInput))){
                            new MaterialDialog.Builder(getViewContext())
                                    .title("提示")
                                    .content("昵称不能为空")
                                    .positiveText("我知道了")
                                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                                        @Override
                                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                            dialog.dismiss();
                                        }
                                    })
                                    .show();
                        }
                    }
                });
                break;
            case 1:
                nav.setTitle("修改身份证");
                tvText.setText("身份证");
                etInput.setHint("请输入身份证");
                tvTips.setText("");
                nav.setRightText("保存", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (TextUtils.isEmpty(getText(etInput))){
                            new MaterialDialog.Builder(getViewContext())
                                    .title("提示")
                                    .content("身份证不能为空")
                                    .positiveText("我知道了")
                                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                                        @Override
                                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                            dialog.dismiss();
                                        }
                                    })
                                    .show();
                        }
                    }
                });
                break;
            case 2:
                nav.setTitle("修改手机号");
                tvText.setText("手机号");
                etInput.setHint("请输入手机号");
                tvTips.setText("");
                nav.setRightText("保存", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (TextUtils.isEmpty(getText(etInput))){
                            new MaterialDialog.Builder(getViewContext())
                                    .title("提示")
                                    .content("手机号不能为空")
                                    .positiveText("我知道了")
                                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                                        @Override
                                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                                            dialog.dismiss();
                                        }
                                    })
                                    .show();
                        }
                    }
                });
                break;
        }
    }

    @Override
    protected CommonInputInfoPresenter createPresenter() {
        return new CommonInputInfoPresenter();
    }


}